package cn.uniquesoft.controller;

import cn.uniquesoft.controller.base.BaseController;
import cn.uniquesoft.manager.ClientManager;
import cn.uniquesoft.page.DataGrid;
import cn.uniquesoft.service.IVisitFilesService;
import cn.uniquesoft.service.IVisitService;
import cn.uniquesoft.vo.UserVO;
import cn.uniquesoft.vo.VisitFilesVO;
import cn.uniquesoft.vo.VisitVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping(value="/visit")
public class VisitController extends BaseController<VisitVO> {
    private IVisitService visitService;
    @Autowired
    private IVisitFilesService visitFilesService;
    public VisitController(IVisitService visitService){
        super();
        this.baseService=visitService;
        this.visitService=visitService;
        this.indexName="visit/index";
    }

    @RequestMapping(value = "/pageQuery")
    @ResponseBody
    public DataGrid pageQuery(VisitVO item) {
        DataGrid dg = new DataGrid();
        UserVO userVO = null;
        try {
            userVO = ClientManager.getInstance().getClient().getUser();
        } catch (Exception e) {

        }
        if (userVO != null) {
            if (userVO.getIvisible() == 1) {

            } else if (userVO.getIvisible() == 2) {
                item.setIbank(userVO.getIorgname());
            } else {
                item.setIcreator(userVO.getIid());
            }
        }
        return this.baseService.pageQuery(item);
    }


    @RequestMapping(value = "/findById")
    @ResponseBody
    public VisitVO findById(int id) {
        VisitVO v = this.baseService.findOneById(id);
        List<VisitFilesVO> flist = this.visitFilesService.findByIpid(id);
        v.setFlist(flist);
        return v;
    }
}
